public class MinSumOfDifferences {
    //用于从三个升序数组中各挑出一个元素a、b、c，使得这三个元素之间的差的绝对值之和最小：
    //暴力的方法
    public static int minSumOfDifferences(int[] A, int[] B, int[] C) {
        int nA = A.length;
        int nB = B.length;
        int nC = C.length;

        int i = 0, j = 0, k = 0;
        int minSum = Integer.MAX_VALUE;

        while (i < nA && j < nB && k < nC) {
            int sumDiff = Math.abs(A[i] - B[j]) + Math.abs(B[j] - C[k]) + Math.abs(C[k] - A[i]);
            minSum = Math.min(minSum, sumDiff);

            if (A[i] <= B[j] && A[i] <= C[k]) {
                i++;
            } else if (B[j] <= A[i] && B[j] <= C[k]) {
                j++;
            } else {
                k++;
            }
        }

        return minSum;
    }

    public static void main(String[] args) {
        int[] A = {1, 4, 7, 10};
        int[] B = {2, 5, 8, 11};
        int[] C = {3, 6, 9, 12};

        int result = minSumOfDifferences(A, B, C);
        System.out.println(result);  // 输出：3
    }
}